<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>微博首页</title>
</head>
<body>
<h1>微博首页</h1>
<div>
    <div v-if="user == ''">
        <a href="/reg.html">注册</a>
        <a href="/login.html">登录</a>
    </div>
    <div v-if="user != ''">
        <h3>欢迎{{user.nick}}回来!</h3>
        <a href="/send.html">发布微博</a>
        <a href="/myweibo.html">我的微博</a>
        <a href="javascript:void(0)" @click="logout()">登出</a>
    </div>
    <div v-for="weibo in arr">
        <h3>
            <a :href="'/datail.html?id='+weibo.id"></a>
            {{weibo.title}}:{{weibo.content}}
        </h3>
        <img :src="weibo.url" style="width: 200px" alt="">
    </div>
</div>
<!--引入axios和vue-->
<script src="js/axios.min.js"></script>
<script src="js/vue.js"></script>
<script>
    let v = new Vue({
        el:"body>div",
        data:{
            arr:[],
            user:""
        },
        created:function (){
            axios.get("/currentUser").then(function (response) {
                v.user = response.data;
            })
            axios.get("/weibo/select/my").then(function (response) {
                v.arr = response.data;
            })
        },
        methods:{
            logout:function () {
                axios.get("logout").then(function () {
                    location.href = "/login.html"
                })
            }
        }
    })
</script>
</body>
</html>